# Contributor: Chloe Kudryavtsev <code@toast.bunkerlabs.net>
# Maintainer: Patrycja Rosa <alpine@ptrcnull.me>
pkgname=quickjs
_pkgver=2023-12-09
pkgver=0.${_pkgver//-}
pkgrel=0
pkgdesc="Small and embeddable Javascript engine"
url="https://bellard.org/quickjs/"
arch="all !s390x !ppc64le" # build segfaults on s390x and ppc64le, requires hardfloat
license="MIT"
options="!check" # disabled because bug/issue on builders
depends_dev="$pkgname=$pkgver-r$pkgrel"
subpackages="$pkgname-dev $pkgname-doc $pkgname-libs $pkgname-static"
source="https://bellard.org/quickjs/quickjs-$_pkgver.tar.xz
	00-makefile.patch
	01-sharedlib.patch
	"
builddir="$srcdir/$pkgname-$_pkgver"

# secfixes:
#   2021-03-27-r5:
#     - CVE-2023-31922

build() {
	for bin in qjs qjsc ; do
		CONFIG_STATIC=y make prefix=/usr $bin
		cp $bin $bin.static
	done
	make clean

	make prefix=/usr VERSION=$pkgver
}

check() {
	make test
}

package() {
	make install prefix="$pkgdir"/usr VERSION=$pkgver
	for bin in qjs.static qjsc.static ; do
		install -Dm755 $bin "$pkgdir"/usr/bin/$bin
	done
	for doc in doc/*.html; do
		install -Dm644 $doc "$pkgdir"/usr/share/doc/quickjs/$doc
	done
}

static() {
	pkgdesc="$pkgdesc - static binaries"
	amove usr/bin/*.static
}

sha512sums="
c63cbff2c2e19512845e4fa2c1306eefcf03316f3e0f29187d6176aaddf840d0423d88429ec73d690da0297c78114092acff76b7f089cb8561214628c1e733c8  quickjs-2023-12-09.tar.xz
256e18095c4c891b2f87ed473b04903a80b769f97f7ef4a60681d6496050f00c21a448f6bf1c858c8a3896dced18bfeec53d981c6f5bd1390d69a12bb91530ff  00-makefile.patch
fb540e21a3cd6bd8119935e0f599bb329fea07a13754bb2d85d620c70d4eeb715ee264fb0c245b3ab5213d54cb106d09b2c9ca94648f1824c757971df4ee1265  01-sharedlib.patch
"
